<?php

class User_Model_User extends Model_Object
{

	/**
	 * get current user id
	 */
	public function getId()
	{
		return $this -> user_id;
	}

	/**
	 * set user password
	 * @param string $string
	 * @return User_Model_User
	 */
	public function setPassword($string)
	{
		$this -> password_salt = Text::random(8);
		$this -> password_hash = $this -> _createPassword($string, $this -> password_salt);
		return $this;
	}

	/**
	 * check if string is password
	 * @param string $string
	 * @return bool
	 */
	public function isPassword($string)
	{
		return (bool)($this -> password_hash === $this -> _createPassword($string, $this -> password_salt));
	}

	/**
	 * generate password from 2 string
	 * @param string $password_string
	 * @param string $hash_string
	 * @return string
	 */

	protected function _createPassword($password_string, $hash_string)
	{
		return sha1($password_string . $hash_string);
	}

	/**
	 * @return string
	 */
	public function __toString()
	{
		return $this -> email;
	}

	/**
	 * @return bool
	 */
	public function isSuper()
	{
		return $this -> role_id && $this -> role_id < 2;
	}

	/**
	 * @return bool
	 */
	public function isAdmin()
	{
		return $this -> role_id && $this -> role_id < 3;
	}

	/**
	 * @return bool
	 */
	public function isModerator()
	{
		return $this -> role_id && $this -> role_id < 4;
	}

	/**
	 * @return bool
	 */
	public function isEditor()
	{
		return $this -> role_id && $this -> role_id < 5;
	}

	/**
	 * @return bool
	 */
	public function isStaff()
	{
		return $this -> role_id && $this -> role_id < 6;
	}

	/**
	 * @return bool
	 */
	public function isMember()
	{
		return $this -> role_id && $this -> role_id < 7;
	}

	public function getEmail()
	{
		return $this -> email;
	}

	public function getTitle()
	{
		return $this -> username;
	}
	
	

}
